/*
 * Copyright 2011 CraneLeeon authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.crane.webtemplate.util;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 *
 * @author CraneLeeon
 */
public class TextUtil {
    public static String cutOutBeginEndQuateMarks(String str){
        if(str == null || str.length() == 0) return str;
        if(str.indexOf("\"") == 0) str = str.substring(1);
        if(str.lastIndexOf("\"") == str.length()-1) str = str.substring(0,str.length()-1);
        return str;
    }

    public static String getUnscaledBigDecimal(BigDecimal value, int limit){
        String unscale = value.setScale(limit,RoundingMode.FLOOR).unscaledValue().toString();
        return unscale;
    }

    public static String fixInitialZeroForInt(int originalValue, int digiTotal){
        String re = originalValue+"";
        for(int add = digiTotal-re.length();add>0;add--){
            re= "0"+re;
        }
        return re;
    }

}
